import { createSlice } from "@reduxjs/toolkit";
import { setStorage, getStorage, removeStorage } from "../storage";

const CACHE_ROUTER = "app_router";

export const counterSlice = createSlice({
  name: "router",
  initialState: {
    routes: getStorage(CACHE_ROUTER, []),
  },
  reducers: {
    setRouter: (state, action) => {
      state.routes = action.payload;
      setStorage(CACHE_ROUTER, action.payload);
    },
    removeRouter: (state) => {
      state.routes = [];
      removeStorage(CACHE_ROUTER);
    },
  },
});

export const { setRouter, removeRouter } = counterSlice.actions;

export default counterSlice.reducer;
